package com.guomao;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public class LocalDateTimeDemo {

    public static void main(String[] args) {

        //获取localdatetime对象

        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);

        LocalDateTime newChina = LocalDateTime.of(1949, 10, 1, 15, 0, 0);

        System.out.println(newChina);
        //2025-05-16T20:31:43.071875100

        System.out.println(newChina.getYear());
        System.out.println(newChina.getHour());
        System.out.println(now.withYear(2049).withHour(10));
        System.out.println(now.plusDays(5));
        LocalDateTime start = LocalDateTime.of(2025, 5, 16, 0, 0);
        LocalDateTime end = LocalDateTime.of(2049, 10, 1, 10, 0);

        long daysBetween = ChronoUnit.DAYS.between(start, end);

        System.out.println(daysBetween);

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        LocalDateTime now2 = LocalDateTime.now();

        String time = now2.format(formatter);

        System.out.println(time);

        Date date = new Date();
//        System.out.println(date);
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        System.out.println(format.format(date));
//        Calendar calendar = Calendar.getInstance();
    }
}
